﻿// 注意，必须设置了run_at=document_start 此段代码才会生效
document.addEventListener('DOMContentLoaded', function() {
  // 检查文档播放区域和视频播放区域
  var player = document.getElementById('playercontainerdiv') || 
              document.getElementById('playervideocontainer')
  if (!player || player.length < 1) return;

  // 向页面注入JS
  console.log('插入脚本')
  injectCustomJs()
  function injectCustomJs(jsPath) {
    jsPath = jsPath || 'inject.js';
    var temp = document.createElement('script');
    temp.setAttribute('type', 'text/javascript');
    // 获得的地址类似：chrome-extension://ihcokhadfjfchaeagdoclpnjdiokfakg/js/inject.js
    temp.src = chrome.extension.getURL(jsPath);
    temp.onload = function() {
      // 放在页面不好看，执行完后移除掉
      this.parentNode.removeChild(this);
    };
    document.head.appendChild(temp);
  }
})